﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.Training.Business.Interfaces;
using Truextend.Training.Model.Entities;
using Truextend.Common.Data;
using Truextend.Training.Business.Dtos;

namespace Truextend.Training.Business
{
    public class UserCourseManager : Repository<UserCourse>, IUserCourseManager
    {
        public UserCourseManager(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
            
        }

        public UserCourse AddUserCourse(UserCourse userCourse)
        {
            this.Add(userCourse);
            return userCourse;
        }

        public IList<UserCourse> GetAllUserCourses(int userId)
        {
            var context = (TrainingEntities)Context;
            var info = from a in context.UserCourses.Include("CourseInstance")
                       where a.UserId == userId
                       select a;
            return info.ToList();
        }

        public IList<UserCourse> GetInstanceUsers()
        {
            var context = (TrainingEntities)Context;
            //DateTime tomorrow = DateTime.Today.AddDays(1);
            var info = from a in context.UserCourses.Include("CourseInstance")
                       where a.CourseInstance.State == "EP"
                       select a;

            foreach (var u in info)
            {
                u.CourseInstance.State = "ES"; //Email Sending
            }

            return info.ToList();
        }
    }
}
